package cn.rocky.offer;

public class offer62 {

    public int lastRemaining(int n, int m) {
        return f(n, m);
    }

    public int f(int n, int m) {
        if (n == 1) {
            return 0;
        }
        int x = f(n - 1,m);
        return (m + x) % n;
    }

    public int lastRemainings(int n, int m) {
        int f = 0;
        for (int i = 2; i != n + 1; ++i) {
            f = (m + f) % i;
        }
        return f;
    }

    public static void main(String[] args) {
        offer62 offer62 = new offer62();
        int i = offer62.lastRemaining(6, 3);
        System.out.println(i);
    }
}
